package com.hspedu.Homework;

import java.nio.charset.StandardCharsets;
import java.util.ArrayList;

public class Homework01 {
    public static void main(String[] args) {
//        News news = new News("奥运会", "多金");
        News news1 = new News("新冠确诊病例超千万，数百万印度教信徒赴恒河“圣浴”引民众担忧");
        News news2 = new News("男子突然想起2个月前钓的鱼还在网兜里，捞起一看赶紧放生");
        ArrayList arrayList = new ArrayList();
        arrayList.add(news1);
        arrayList.add(news2);
        int size = arrayList.size();
        for (int i = size - 1; i >= 0; i--) {
            News news = (News) arrayList.get(i);
            String title = news.getTitle();
            String title2=processTitle(title);
            System.out.println(title2);
        }

    }


    public static String processTitle(String title){
//        char[] charTitle=title.toCharArray();
        String proTitle = null;
        if (title==null){
            return "";
        }
        if (title.length()>15){
            proTitle=title.substring(0,15)+"...";
            return proTitle;
        }else {return title;}
    }}

class News{
    private String title;
    private String contents;

    public News(String title) {
        this.title = title;
    }

    public News(String title, String contents) {
        this.title = title;
        this.contents = contents;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getContents() {
        return contents;
    }

    public void setContents(String contents) {
        this.contents = contents;
    }

    @Override
    public String toString() {
        return title
               ;
    }
}
